package com.link.base.base.appmenuurls.service;

import javax.annotation.Resource;

import com.link.base.base.appmenuurls.utils.RunAddAppPageUrl;
import com.link.base.base.monitor.MonitorObjectChange;
import com.link.base.base.pageurls.service.PageUrlsService;
import com.link.base.core.basic.util.ThreadPoolExecutorSingleton;
import com.link.core.basic.interceptor.SecurityInterceptor;
import org.springframework.stereotype.Service;
import com.link.base.base.appmenuurls.dao.mybatis.mapper.AppMenuUrlsMapper;
import com.link.base.base.appmenuurls.model.AppMenuUrls;
import com.link.core.basic.dao.mapper.BasicMapper;
import com.link.core.basic.service.BasicServiceImpl;

import java.util.List;
import java.util.concurrent.ThreadPoolExecutor;

/**
 * app菜单下页面路径
 *
 * @author 秦学刚
 * @date 2020-07-07 16:19:35
 */
@Service
public class AppMenuUrlsServiceImpl extends BasicServiceImpl<AppMenuUrls> implements AppMenuUrlsService {

    @Resource
    private AppMenuUrlsMapper    appMenuUrlsMapper;
    @Resource
    private PageUrlsService pageUrlsService;
    @Resource
    private MonitorObjectChange monitorObjectChange;

    @Override
    public BasicMapper<AppMenuUrls> getBasicMapper() {
        return appMenuUrlsMapper;
    }


    @Override
    public List<String> getUrlsByAppDuty(AppMenuUrls appMenuUrls) throws Exception {
        // step1 查找到职责下面的所有的菜单
        // step2 根据步骤一查找到的菜单，查找到安全性菜单以及 url信息
        // step3 根据安全性菜单以及url信息进行筛选出最后的url信息
        // step4 根据查找出来的url进行剔重处理
        return appMenuUrlsMapper.getUrlsByAppDuty(appMenuUrls);
    }


    @Override
    public void addAppPageUrlAll() throws Exception {
        ThreadPoolExecutor executor = ThreadPoolExecutorSingleton.getInstance();
        executor.execute(new RunAddAppPageUrl(SecurityInterceptor.token.get(),
                SecurityInterceptor.tempUser.get(),SecurityInterceptor.tempEnterpirse.get()));
    }

    @Override
    public void beforUpsert(AppMenuUrls appMenuUrls) throws Exception {
        // 这里需要监控菜单下URL的新增/修改/批量编辑,当变化时需要触发职责url变化
        monitorObjectChange.dutyChange(appMenuUrls,"APP");
    }

    @Override
    public void beforDelete(AppMenuUrls appMenuUrls) throws Exception {
        // 这里需要监控菜单下URL的删除,当变化时需要触发职责url变化
        monitorObjectChange.dutyChange(appMenuUrls,"APP");
    }
}